//
//  EditNoteView.m
//  ProjectDemo
//
//  Created by IOS3 on 2018/12/28.
//  Copyright © 2018 IOS3. All rights reserved.
//

#import "EditNoteView.h"




@interface EditNoteView () <UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *tipLabel;
@property (weak, nonatomic) IBOutlet UIButton *ensureButton;
@property (weak, nonatomic) IBOutlet UILabel *holderLabel;
@property (weak, nonatomic) IBOutlet UIView *tipLabelBackgroundView;

@property (weak, nonatomic) IBOutlet UIView *textBackgroundView;
@property (weak, nonatomic) IBOutlet UITextView *textView;


@end
@implementation EditNoteView



- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setupUI];
}

+ (instancetype)createInstance {
    return [[NSBundle mainBundle] loadNibNamed:@"EditNoteView" owner:nil options:nil].lastObject;
}



#pragma mark - button Action

- (IBAction)cancleButtonClick:(UIButton *)sender {
    if (self.cancelButtonTaped) {
        self.cancelButtonTaped();
    }
}
- (IBAction)ensureButtonClick:(UIButton *)sender {
    if (self.ensureButtonTaped) {
        self.ensureButtonTaped(self.textView.text);
    }
}
- (IBAction)deleteNoteButtonClick:(UIButton *)sender {
    if (self.deleteButtonTaped) {
        self.deleteButtonTaped();
    }
}






#pragma mark - 设置UI
- (void)setupUI {
    self.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.3];

    self.textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.textView.delegate = self;
    
    self.textBackgroundView.layer.cornerRadius = 4;
    self.textBackgroundView.layer.borderColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0].CGColor;
    self.textBackgroundView.layer.borderWidth = 1.0;
    self.textBackgroundView.layer.masksToBounds = true;;
    
    self.ensureButton.contentEdgeInsets = UIEdgeInsetsMake(9, 12, 9, 12);
    self.ensureButton.layer.cornerRadius = 2;
    self.ensureButton.layer.masksToBounds = true;
    
    self.tipLabelBackgroundView.layer.cornerRadius = 5;
    self.tipLabelBackgroundView.layer.masksToBounds = true;
    
    // 设置提示文字
    NSString *tipString = @"您随时随地都可以获得它的帮助。无论是目标设定、时间管理资源分配、创新思考、会议报告，还是人生规划...";
    CGFloat colorValue = 102 / 255.0;
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
    [paragraph setLineSpacing:10];
    NSDictionary *attrParam = @{
                                NSFontAttributeName : [UIFont systemFontOfSize:12],
                                NSForegroundColorAttributeName : [UIColor colorWithRed:colorValue green:colorValue blue:colorValue alpha:1.0],
                                NSParagraphStyleAttributeName : paragraph
                                };
    NSAttributedString *attrTip = [[NSAttributedString alloc] initWithString:tipString attributes:attrParam];
    [self.tipLabel setAttributedText:attrTip];
}


#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
    self.holderLabel.hidden = (textView.text.length > 0);
}
@end
